package com.otod.commons.tools;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.otod.commons.constants.PropertiesConstant;

/**
 * open office 服务
 * @author jqiu
 *
 */
public class OpenOfficeServer {
	private static Logger logger = LoggerFactory.getLogger(OpenOfficeServer.class);
	
	private static String OpenOfficeCmd = UserEnv.getProp(PropertiesConstant.OPENOFFICE_START_COMMAND); // 这里是OpenOffice的安装目录,
	private static Process pro = null;
	
	/**
	 * 启动OpenOffice的服务
	 */
	public static void start(){
		try {
			pro = Runtime.getRuntime().exec(OpenOfficeCmd);
		} catch (IOException e) {
			logger.error("无法找到open office，请确认配置是否正确！", e);
		} catch (Exception e) {
			logger.error("open office启动发生错误！", e);
		}
	}
	
	/**
	 * 停止OpenOffice服务
	 */
	public static void stop(){
		try {
			if(pro != null){
				pro.destroy();
			}
		} catch (Exception e) {
			logger.error("open office服务关闭发生错误！", e);
		}
	}
}
